
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int pathX[1000];
int pathY[1000];
int bestPathX[1000];
int bestPathY[1000];

int curPathPointNum;
int gPathCount = 0;
int visited[10][10] = {0};
int maze[10][10] = {0};
int minPathLen = 1000000000;
int N = 5;
void InitMaze() 
{ 
	for (int i = 0;i<10;i++)
	{
		for (int j = 0;j<10;j++)
		{
			maze[i][j] = 1;
		}
	}
	for (int i = 1;i <= N;i++)
	{
		for (int j = 1;j <= N;j++)
		{
			cin >> maze[i][j];
		}
	}
}



void PrintBestPath()
{
	for (int i = 0;i < minPathLen + 1;i++)
	{
		cout << "(" << bestPathX[i] - 1 <<", "<< bestPathY[i] - 1<<")"<<endl;
	}
}
void SaveBestPath()
{
	for (int i = 0;i < curPathPointNum;i++)
	{
		bestPathX[i] = pathX[i];
		bestPathY[i] = pathY[i];
	//	cout << "(" << bestPathX[i] - 1 <<", "<< bestPathY[i] - 1<<")"<<endl;
	}
}

void Go(int posX,int posY,int endX,int endY)
{
	if (posX == endX && posY == endY)
	{
		if (curPathPointNum - 1 < minPathLen)
		{
			minPathLen = curPathPointNum - 1;
			SaveBestPath();
		}
		return;
	}

	if (curPathPointNum - 1 >= minPathLen)
	{
		return;
	}
	static int dx[4] = {1,-1,0,0};
	static int dy[4] = {0,0,1,-1};

	for (int i = 0;i<4;i++)
	{
		int newX = posX + dx[i];
		int newY = posY + dy[i];
		if (maze[newX][newY] == 0 && !visited[newX][newY])
		{
			curPathPointNum ++;
			visited[newX][newY] = 1;
			pathX[curPathPointNum - 1] = newX;
			pathY[curPathPointNum - 1] = newY;
			Go(newX,newY,endX,endY);
			visited[newX][newY] = 0;
			curPathPointNum --;
		}
	}
}

int main3984()
{
	InitMaze();
	int startX = 1;
	int startY = 0;
	int endX = 5;
	int endY = 5;
	curPathPointNum = 0;
	Go(startX,startY,endX,endY);
	PrintBestPath();
	return 0;
}